package com.xyd.servlet;

import com.xyd.service.NewsService;
import com.xyd.service.impl.NewsServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 86186
 */
@WebServlet("/NewsDelServlet")
public class NewsDelServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String enIdStr = request.getParameter("enId");
        long enId =Long.parseLong(enIdStr);

        NewsService newsService=new NewsServiceImpl();

        Boolean flag=newsService.delNews(enId);

        if (flag){
            response.sendRedirect("NewsServlet?pageIndex=0");
        }
        else {
            response.sendRedirect("manage/index.html");
            System.out.println("删除错误!");
        }

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }
}
